some features and improvements#3
Conversation
…apiadmin/cppchess_engine into test_stablerel_thread1
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 55b4b0e9a2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| searchThread = std::thread([ss = std::move(ss)]() mutable { | ||
| search::search(pos, parse_limits(ss)); |
There was a problem hiding this comment.
Snapshot
pos before launching the search thread
The worker is started with search::search(pos, ...), where pos is a mutable global also written by handlePosition(). Because loop() keeps accepting commands after go, a position ... command arriving before stop/join can mutate pos while the search thread is reading/copying it, which is a data race and can produce analysis for a mixed position. Capture a board snapshot before spawning the thread (or guard pos with synchronization).
Useful? React with 👍 / 👎.
| if (searchThread.joinable()) { | ||
| search::stop(); | ||
| searchThread.join(); | ||
| } |
There was a problem hiding this comment.
Prevent TT option changes during asynchronous search
After go returns, the command loop can still process setoption; in this codebase, Hash/Clear Hash options in main.cpp call search::tt.resize()/clear(), while the worker thread simultaneously calls tt.lookup()/store() in search.cpp. This unsynchronized mutation can free or overwrite TT storage during search, causing crashes or corrupted results when options are changed mid-search. Gate mutating commands until the worker is joined, or protect TT with proper synchronization.
Useful? React with 👍 / 👎.
| return limits; | ||
| } | ||
| void handleGo(std::istringstream &ss) { search::search(pos, parse_limits(ss)); } | ||
| std::thread searchThread; |
There was a problem hiding this comment.
Join
searchThread when the input loop exits
The global std::thread is joined on go/stop/quit, but not when loop() ends via EOF. If stdin closes after a go command, searchThread can remain joinable, and destroying a joinable std::thread triggers std::terminate at shutdown (even if the worker already finished). Add a join on the EOF path or use a thread type with automatic joining semantics.
Useful? React with 👍 / 👎.
Passed STC:
Passed LTC: